package com.cy.chatTest.controller;

import com.cy.chatTest.bin.BaseEntity;
import com.qiniu.util.Auth;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/qiniu")
public class Qiniu {

    static final String accessKey = "dsuWgEJfA3xgrFS2By7I8k3m5tQrPM6JYIsk_UNv";
    static final String secretKey = "BFCMv_zlJVl7sKYRXMMZKsZPFLIEEfPbIZSrYQp5";


    //String headBucket = "head-img";//头像空间名


    /**
     * 获取上传图片的token(覆盖已存在的图)
     * @param bucketName
     * @return
     */
    @PostMapping("getQiniuToken")
    public BaseEntity getQiniuToken(String bucketName,String imageName){
        Auth auth = Auth.create(accessKey, secretKey);
        String upToken = auth.uploadToken(bucketName,imageName);
        Map<String,String> map = new HashMap<>();
        map.put("qiniuToken",upToken);
        return new BaseEntity(true,map);
    }


}
